<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('会员信息')"/>
</head>
<body class="gray-bg">

<div class="container-div ui-layout-center">
    <div class="row">
        <div class="form-content">
            <form id="user-form" class="form-horizontal">
                <!--<input type="hidden" id="deptId" name="deptId">-->
                <input type="hidden" id="parentId" value="100" name="parentId">
                <div class="row">
                    <div class="col-sm-4">
                        <div class="form-group">
                            <label class="col-sm-4 control-label">编号：</label>
                            <div class="col-sm-8">
                                <div class="input-group">
                                    <input type="text" name="userId" class="form-control"/>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-4">
                        <div class="form-group">
                            <label class="col-sm-4 control-label">用户类型：</label>
                            <div class="col-sm-8">
                                <select id="orderPrice" name="orderPrice" class="form-control">
                                    <option value="">所有</option>
                                    <option value="100">假人</option>
                                    <option value="200">真人</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-4">
                        <div class="form-group">
                            <label class="col-sm-4 control-label">会员手机号：</label>
                            <div class="col-sm-8">
                                <div class="input-group">
                                    <input type="text" name="userName" class="form-control" style="width: 316px;"/>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!--                    <div class="col-sm-4">-->
                    <!--                        <div class="form-group">-->
                    <!--                            <label class="col-sm-4 control-label">会员电话：</label>-->
                    <!--                            <div class="col-sm-8">-->
                    <!--                                <div class="input-group">-->
                    <!--                                    <input type="text" name="phonenumber" class="form-control" style="width: 316px;"/>-->
                    <!--                                </div>-->
                    <!--                            </div>-->
                    <!--                        </div>-->
                    <!--                    </div>-->
                    <div class="col-sm-4 col-md-offset-1">
                        <div class="form-group">
                            <a class="btn btn-success btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-success btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </div>
                    </div>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="addBusiness()" shiro:hasPermission="system:user:addBusiness">
                <i class="fa fa-plus"></i> 新增会员
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="false"></table>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:user:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:user:remove')}]];
    var resetPwdFlag = [[${@permission.hasPermi('system:user:resetPwd')}]];
    var datas = [[${@dict.getType('sys_normal_disable')}]];
    var prefix = ctx + "channel/vwBusinessCashStat";

    $(function () {
        queryUserList();
    });

    function queryUserList() {
        var url = prefix + "/list";
        // if (location.href.indexOf("127.0.0.1") > -1) {
        //     url = "vwBusinessCashStat/list";
        // }
        var options = {
            url: url,
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            importUrl: prefix + "/importData",
            importTemplateUrl: prefix + "/importTemplate",
            sortName: "userId",
            sortOrder: "desc",
            modalName: "用户",
            columns: [{
                checkbox: true
            },
                {
                    title: '操作',
                    align: 'center',
                    width: 500,
                    formatter: function (value, row, index) {
                        var role = [[${role}]]
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="editBusiness(\'' + row.userId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + resetPwdFlag + '" href="#" onclick="pauseOrder(\'' + row.userId + '\')"><i class="fa fa-key"></i>卡单</a>');
                        if (row.orderPrice === 100 || role === 'admin2' || role === 'admin') {
                            actions.push('<a class="btn btn-success btn-xs ' + resetPwdFlag + '" href="#" onclick="addOrder(\'' + row.userId + '\')"><i class="fa fa-key"></i>上分</a>');
                        }
                        actions.push('<a class="btn btn-success btn-xs ' + resetPwdFlag + '" href="#" onclick="resetOrderSum(\'' + row.userId + '\')"><i class="fa fa-key"></i>重置单数</a>');
                        actions.push('<a class="btn btn-success btn-xs ' + resetPwdFlag + '" href="#" onclick="updateBankAddress(\'' + row.userId + '\')"><i class="fa fa-key"></i>收款地址</a>');
                        return actions.join(' ');
                    }
                },
                {
                    field: 'orderPrice',
                    title: '类型',
                    formatter: function (value, row, index) {
                        return value === 100 ? '<span style="color: red">假人</span>' : '<span>真人</span>'
                    }
                },
                {
                    field: 'userId',
                    title: '会员编号',
                    sortable: false
                },
                {
                    field: 'invitationCode',
                    title: '邀请码',
                },
                {
                    field: 'userName',
                    title: '会员手机号',
                    sortable: true
                },
                {
                    field: 'daySum',
                    title: '当前抢单数',
                    sortable: true
                },
                // {
                //     field: 'phonenumber',
                //     title: '会员电话'
                // },
                {
                    field: 'rootUserName',
                    title: '业务员',
                    sortable: true
                },
                {
                    field: 'parentUserName',
                    title: '直接上级',
                }, {
                    field: 'finalCash',
                    title: '可用金额',
                    formatter: function (value, row, index) {
                        return (value - row.pauseOrderPrice).toFixed(2)
                    }
                },
                {
                    field: 'amountSum',
                    title: '总金额',
                    sortable: true
                },
                {
                    field: 'paySum',
                    title: '充值金额',
                    sortable: true
                },
                {
                    field: 'frzzingCash',
                    title: '提现中金额',
                    sortable: true
                },
                {
                    field: 'hasCashSum',
                    title: '已提现金额',
                    sortable: true
                },
                {
                    field: 'batchTaskIncomeCash',
                    title: '当前抢单佣金',
                    sortable: true
                },
                {
                    field: 'incomeCash',
                    title: '总佣金',
                    sortable: true
                }, {
                    field: 'firstSum',
                    title: '一级代理数',
                    sortable: true
                },
                {
                    field: 'systemWalletAddress',
                    title: '系统钱包地址',
                    sortable: true
                },
                {
                    field: 'userWalletAddress',
                    title: '用户钱包地址',
                    sortable: true
                },


                // {
                // 	field: 'secondSum',
                // 	title: '二级代理数',
                // 	sortable: true
                // }, {
                // 	field: 'thirdSum',
                // 	title: '三级代理数',
                // 	sortable: true
                // },
                // {
                // 	field: 'childSum',
                // 	title: '代理总数',
                // 	sortable: true
                // },
                // {
                // 	field: 'todayClickIncomeCash',
                // 	title: '今日抢单金额',
                // 	sortable: true
                // },
                {
                    field: 'todayTaskIncomeCout',
                    title: '今日抢单数',
                    sortable: true
                }, {
                    field: 'createTime',
                    title: '注册时间',
                    visible: false
                }]
        };
        $.table.init(options);
    }

    function addOrder(userId) {
        layer.open({
            title: '请输入金额为',
            content: '<div style="color: black;"><label>请输入金额为:&nbsp;&nbsp;</label><input id="phoneCode" type="text" placeholder="请输入金额" style="width: 200px"></div>\n',
            btn: ['确定', '取消'],
            btn1: function (index, layero) {
                var val = $('#phoneCode').val();
                if (val.trim() === '') {
                    alert('请输入金额');
                    return false;
                }
                var url = ctx + "channel/channelOrder/addOrder";
                var data = {"userId": userId, "amount": val, type: '手动上分'};
                $.operate.submit(url, "post", "json", data);
            },
            btn2: function (index, layero) {
            }
        });
    }

    function resetOrderSum(userId) {
        // 重置刷单数
        layer.open({
            area: ['350px', '200px'],
            title: '请输入当前已刷单数',
            content: '<div style="color: black;"><label>请输入当前已刷单数为:&nbsp;&nbsp;</label><input id="num" value="0" type="text" placeholder="请输入当前已刷单数" style="width: 250px"></div>',
            btn: ['确定', '取消'],
            btn1: function (index, layero) {
                var val = $('#num').val();
                if (val.trim() === '') {
                    alert('请输入金额');
                    return false;
                }
                var url = ctx + "channel/businessInfoOrder/edit";
                var data = {"userId": userId, daySum: val.trim()};
                $.operate.submit(url, "post", "json", data);
            },
            btn2: function (index, layero) {
            }
        });
    }

    function updateBankAddress(userId) {
        layer.open({
            area: ['350px', '200px'],
            title: '请输入收款地址',
            content: '<div style="color: black;"><label>请输入收款地址为:&nbsp;&nbsp;</label><input id="num" value="" type="text" placeholder="请输入收款地址" style="width: 250px"></div>',
            btn: ['确定', '取消'],
            btn1: function (index, layero) {
                var val = $('#num').val();
                if (val.trim() === '') {
                    alert('请输入地址');
                    return false;
                }
                var url = ctx + "channel/bankInfo/updateSelf";
                var data = {"userId": userId, bankNo: val.trim()};
                $.operate.submit(url, "post", "json", data);
            },
            btn2: function (index, layero) {
            }
        });
    }

    function pauseOrder(userId) {
        // layer.open({
        //     area: ['650px', '400px'],
        //     title: '请输入卡单金额',
        //     content: '<div><div style="color: black;"><label>请输入金额为:&nbsp;&nbsp;</label><input id="phoneCode" type="text" placeholder="请输入金额" style="width: 400px"></div>' +
        //         '<div style="color: black;"><label>请输卡第几单:&nbsp;&nbsp;</label><input id="orderNum" type="text" placeholder="请输入要卡第几单" style="width: 400px"></div>' +
        //         '<div style="color: black;"><label>请输卡单倍数:&nbsp;&nbsp;</label><input id="orderTimes" type="text" placeholder="请输入倍数" style="width: 400px"></div></div>\n',
        //     btn: ['确定', '取消'],
        //     btn1: function (index, layero) {
        //         var val = $('#phoneCode').val();
        //         var orderNum = $('#orderNum').val();
        //         var orderTimes = $('#orderTimes').val();
        //
        //         if (val.trim() === '') {
        //             alert('请输入金额');
        //             return false;
        //         }
        //         if (orderNum.trim() === '') {
        //             alert('请输入卡第几单');
        //             return false;
        //         }
        //         if (orderTimes.trim() === '') {
        //             alert('请输卡单倍数');
        //             return false;
        //         }
        //
        //         var url = ctx + "channel/channelOrder/pauseOrder";
        //         var data = {"userId": userId, "amount": val, orderTimes: orderTimes, orderNum: orderNum};
        //         $.operate.submit(url, "post", "json", data);
        //     },
        //     btn2: function (index, layero) {
        //     }
        // });

        var url = ctx + "channel/businessPauseOrderSetting/list/view/" + userId;
        $.modal.openTab(userId + "：卡单设置", url);
    }

    function resetPayPwd(id) {
        $.modal.confirm("确认要重置密码吗?", function () {
            var url = ctx + "channel/businessInfo/resetPayPwd";
            var data = {"id": id, "code": ''};
            $.operate.submit(url, "post", "json", data);
        });
    }

    function editBusiness(id) {
        var url = ctx + "system/user/editBusiness/" + id;
        $.modal.openTab("修改会员", url);
    }

    function pauseOrderSetting(id) {
        var url = ctx + "channel/businessPauseOrderSetting/editBusiness/" + id;
        $.modal.openTab("修改会员", url);
    }

    function addBusiness() {
        var url = ctx + "system/user/addBusiness";
        $.modal.openTab("新增会员", url);
    }

    function querySubBusiness(id) {
        var url = ctx + "system/user/businessList/" + id;
        $.modal.openTab("查询下级商户", url);
    }

    function querySubScore(id) {
        var url = ctx + "system/user/scoreList/" + id;
        $.modal.openTab("查询下级代理", url);
    }

    function queryDeptTree() {
        var url = ctx + "system/dept/treeData";
        var options = {
            url: url,
            expandLevel: 1,
            onClick: zOnClick
        };
        $.tree.init(options);

        function zOnClick(event, treeId, treeNode) {
            $("#deptId").val(treeNode.id);
            $("#parentId").val(treeNode.pId);
            $.table.search();
        }
    }

    $('#btnExpand').click(function () {
        $._tree.expandAll(true);
        $(this).hide();
        $('#btnCollapse').show();
    });

    $('#btnCollapse').click(function () {
        $._tree.expandAll(false);
        $(this).hide();
        $('#btnExpand').show();
    });

    $('#btnRefresh').click(function () {
        queryDeptTree();
    });


    /* 用户管理-重置密码 */
    function resetPwd(userId) {
        $.modal.confirm("确认要重置密码吗?", function () {
            var url = prefix + '/resetPwd';
            var data = {"userId": userId, "password": md5("123456")};
            $.operate.submit(url, "post", "json", data);
        });
    }


    /* 用户状态显示 */
    function statusTools(row) {
        if (row.status == 1) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.userId + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.userId + '\')"></i> ';
        }
    }

    /* 用户管理-停用 */
    function disable(userId) {
        $.modal.confirm("确认要停用用户吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"userId": userId, "status": 1});
        })
    }

    /* 用户管理启用 */
    function enable(userId) {
        $.modal.confirm("确认要启用用户吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"userId": userId, "status": 0});
        })
    }
</script>
</body>
</html>